﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Text;
using System.IO;
using System.Collections.Generic;
using EPiServer.Web.Hosting;
using System.Web.Hosting;
using EPiServer.Research.MobileCenter.Core;
using System.Runtime.Serialization.Json;
using EPiServer.Research.MobileCenter.JSON;

namespace EPiServer.WebServices.MobileCenter
{

    /// <summary>
    /// Utility members for EPiServer
    /// </summary>
    [WebService(Namespace="EPiServer.Research",
                Description="Utility functions for EPiServer, giving mobilecenter information about gadgets.")]
    public class iPhoneGadgets : System.Web.Services.WebService
    {

        /// <summary>
        /// Configurations the JSON XML for the mobile device to show what it needs
        /// </summary>
        /// <returns></returns>
        [WebMethod(Description="Returns all MobileCenter gadgets information")]
        public string ConfigurationXml()
        {
            JSONGadgetHolder gadgetHolder = MobileCenterFactory.Instance.GetAllJsonForMobileCenter();
            MemoryStream stream1 = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(JSONGadgetHolder));
            ser.WriteObject(stream1, gadgetHolder);
            string finalString = String.Empty;
            stream1.Position = 0;

            using(StreamReader sr = new StreamReader(stream1)){

                finalString = sr.ReadToEnd();
            }
            return finalString;
        }



        public iPhoneGadgets()
        {
            //CODEGEN: This call is required by the ASP.NET Web Services Designer
            InitializeComponent();
        } 
  
        //Required by the Web Services Designer 
        private IContainer components = null;
        private void InitializeComponent()
        {
        }

        protected override void Dispose( bool disposing )
        {
            if(disposing && components != null)
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
    }
} 